package com.gx.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        /*fieldName 要设置的属性名*/
        /*fieldVal 要设置的属性值*/
        /*metaObject 源数据*/
        /*this.strictInsertFill(metaObject, "CreateTime", String.class, new Date().toString());*/
        this.setFieldValByName("CreateTime",new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()),metaObject);
        this.setFieldValByName("UpdateTime",new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()),metaObject);
        this.setFieldValByName("version",1,metaObject);
        this.setFieldValByName("deleted",0,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        /*this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());*/
        this.setFieldValByName("UpdateTime",new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()),metaObject);
    }
}
